﻿using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using SmarterCharger.Library.Infrastructure;
using SmarterCharger.Library.Model;
using SmarterCharger.Library.Repositories;
using SmarterCharger.Library.Repositories.Interfaces;
using SmarterCharger.Library.Tests.Unit.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace SmarterCharger.Library.Tests.Unit.EnergyDeviceRepositorySpecifications
{
    public abstract class WhenGetEnergyDevices : TestBaseAsync<HttpResponseResult<IEnumerable<EnergyDevice>>>
    {
        protected IEnergyDeviceRepository EnergyDeviceRepository{ get; private set; }
        protected virtual string Username { get { return "dummy-username"; } }
        protected virtual string Password { get { return "dummy-password"; } }

        protected override void Arrange()
        {
            EnergyDeviceRepository = new EnergyDeviceRepository();
        }

        protected override Task<HttpResponseResult<IEnumerable<EnergyDevice>>> Act()
        {
            return EnergyDeviceRepository.GetEnergyDevices(Username, Password);
        }
    }

    [TestClass]
    public class WhenGetEnergyDevicesGivenUsernameIsEmpty : WhenGetEnergyDevices
    {
        protected override string Username
        {
            get
            {
                return string.Empty;
            }
        }


        [TestMethod]
        public void ThenAnArgumentNullExceptionShouldBeThrown()
        {
            var argumentNullException = BaseException as ArgumentNullException;
            Assert.IsNotNull(argumentNullException);
            Assert.AreEqual("username", argumentNullException.ParamName);
        }
    }

    [TestClass]
    public class WhenGetEnergyDevicesGivenPasswordIsEmpty : WhenGetEnergyDevices
    {
        protected override string Password
        {
            get
            {
                return string.Empty;
            }
        }

        [TestMethod]
        public void ThenAnArgumentNullExceptionShouldBeThrown()
        {
            var argumentNullException = BaseException as ArgumentNullException;
            Assert.IsNotNull(argumentNullException);
            Assert.AreEqual("password", argumentNullException.ParamName);
        }
    }
}
